program Project1;

{$APPTYPE CONSOLE}
uses
  SysUtils;
type
  pelement = ^element;
  element = record
    value : Integer;
    next : pelement;
  end;


var
  fin : textfile;
  n, i, a: integer;
  head : pelement;
  flag : boolean;

function Delete (var head : pelement):integer;
var tmp : pelement;
begin
  if (head <> nil) then
  begin
    tmp := head^.next;
    Delete := head^.value;
    Dispose (head);
    head := tmp;
  end;
end;

procedure PrintList (head : pelement);
var current : pelement;
begin
  current := head;
  while (current <> nil) do
  begin
    Writeln (current^.value);
    current := current^.next;
  end;
end;

procedure Add (var head : pelement; num : integer);
var tmp : pelement;
begin

  begin
    tmp := head;
    New (head);
    head^.value := num;
    head^.next := tmp;
  end;
end;

begin
  assignfile(fin, 'input.txt');
  reset(fin);
  readln(fin, n);
  flag:=false;

  for i := 0 to n-1 do
  begin
    read (fin, a);
    Add(head, a);
  end;


  for i := 0 to n-1 do
  begin
    if (head=nil) or (head^.next=nil) or (head^.next^.next=nil) then
    begin
      writeln('Error!');
      break;
    end;
    if (head^.next^.next^.next<>nil) then
    begin
      Delete(head^.next^.next^.next);
      flag:=true;
      break;
    end;
    head:=head^.next;
  end;

  if (flag) then
    PrintList(head);

  for i := 0 to n-1 do
    Delete(head);

  closefile(fin);
  readln;
end.
